package cc.ufinity.networkdiagnose.widget;

import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import cc.ufinity.networkdiagnose.adapter.MyAdapter;
import cc.ufinity.networkdiagnose.view.R;

public class SettingWidget extends GeneralTestWidget {
    private ListView list;
    private Activity ctx;  

    public SettingWidget(Activity context) {
        super(context);
        this.ctx = context;
        inflate(context, R.layout.setting_widget, this);
        list=(ListView)findViewById(R.id.mylist);
        String[] menu = getResources().getStringArray(R.array.settingGridView);
       // int[] icons = new int[] { R.drawable.ftp_settings, R.drawable.people, R.drawable.phone, R.drawable.http_test, R.drawable.ping, R.drawable.upload_file };
        int[] icons = new int[] {R.drawable.people, R.drawable.phone, R.drawable.http_test, R.drawable.ping, R.drawable.upload_file };
        ListAdapter adapter = new MyAdapter(ctx, icons, menu);
        list.setAdapter(adapter);
        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View v, int index, long id) {
                switch (index) {
//                case 0:
//                    ftpConfig();
//                    break;
                case 0:
                    accountConfig();
                    break;
                case 1:
                    mobileConfig();
                    break;
                case 2:
                	httpConfig();
                	break;
                case 3:
                	pingConfig();
                	break;
                case 4:
                	doUpload();
                	break;
                }             
            }
        });
    }

    private void mobileConfig() {
        MyMobileCfgWidget mw = new MyMobileCfgWidget(ctx);
        ctx.setContentView(mw);
    }

    private void ftpConfig() {
        FtpConfigWidget fw = new FtpConfigWidget(ctx);
        ctx.setContentView(fw);
    }

    private void accountConfig() {
        AccountConfigWidget af = new AccountConfigWidget(ctx);
        ctx.setContentView(af);
    }
    
    private void httpConfig() {
    	HttpConfigWidget af = new HttpConfigWidget(ctx);
        ctx.setContentView(af);
    }
    
    private void pingConfig() {
        PingConfigWidget af = new PingConfigWidget(ctx);
        ctx.setContentView(af);
    }
    private void doUpload() {
        FilesUploadWidget fu = new FilesUploadWidget(ctx);
        ctx.setContentView(fu);
    }

}
